import type { Preset, SourceCodeTransformer } from 'unocss'
import {
  defineConfig,
  presetAttributify,
  presetUno,
  transformerDirectives,
  transformerVariantGroup,
} from 'unocss'

import presetIcons from '@unocss/preset-icons'

import {
  presetApplet,
  presetRemToRpx,
  transformerApplet,
  transformerAttributify,
} from 'unocss-applet'

const presets: Preset[] = []
const transformers: SourceCodeTransformer[] = []

if (process.env.UNI_PLATFORM === 'h5') {
  presets.push(presetUno())
} else {
  presets.push(presetApplet())
  presets.push(presetRemToRpx())

  transformers.push(transformerAttributify())
  transformers.push(transformerApplet())
}

export default defineConfig({
  presets: [
    ...presets,
    presetAttributify(),
    presetIcons(),
  ],
  rules: [
    [/^width-(\d+)$/, ([, d]) => ({ width: `${d}%` })],
    [/^height-(\d+)$/, ([, d]) => ({ height: `${d}%` })],
    [/^left-(\d+)$/, ([, d]) => ({ left: `${d}%` })]
  ]
  // transformers: [
  //   transformerDirectives(),
  //   transformerVariantGroup(),
  //   ...transformers,
  // ],
})